package com.woniuxy.microgoodsserver.auctionmag.mapper;

import com.woniuxy.microgoodsserver.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface MallSettingMapper {

    //商城设置通过id查询
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = int.class),
            @Result(property = "keyWord",column = "key_word",javaType = String.class),
            @Result(property = "goodsLabel",column = "goods_label",javaType = int.class),
            @Result(property = "freight",column = "freight",javaType = int.class),
            @Result(property = "sort",column = "sort",javaType = int.class),
            @Result(property = "describes",column = "describes",javaType = String.class),
            @Result(column = "fk_im_id",property = "imageBean",javaType = ImageBean.class,
                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.ImageMapper.imageFindAllById",fetchType = FetchType.LAZY))
    })
    @Select("select id,key_word,goods_label,freight,sort,describes,fk_im_id from" +
            " t_mall_setting_info where id = #{id} and del_status= 0")
    MallSettingBean mallSettingFindAllById(@Param("id")int id);





    //商城设置增加
    @Options(useGeneratedKeys = true,keyProperty = "i.id")
    @Insert("insert into t_mall_setting_info " +
            "(key_word,goods_label,freight,sort,describes,fk_im_id,del_status)" +
            " values(#{m.keyWord},#{m.goodsLabel},#{m.freight},#{m.sort}," +
            "#{m.describes},#{m.imageBean.id},'0')")
    int saveMall(@Param("m") MallSettingBean mallSettingBean);


    //商城设置修改
    @Update("<script>" +
            "update t_mall_setting_info" +
            "<set>" +
            "<if test='m.keyWord != null'>" +
            " key_word = #{m.keyWord}," +
            "</if>" +
            "<if test='m.goodsLabel != null'>" +
            " goods_label = #{m.goodsLabel}," +
            "</if>" +
            "<if test='m.freight != null'>" +
            " freight = #{m.freight}," +
            "</if>" +
            "<if test='m.sort != null'>" +
            " sort = #{m.sort}," +
            "</if>" +
            "<if test='m.describes != null'>" +
            " describes = #{m.describes}," +
            "</if>" +
            "<if test='m.imageBean.id != null'>" +
            " fk_im_id = #{m.imageBean.id}," +
            "</if>" +
            "</set>" +
            "where id = #{m.id}" +
            "</script>")
    int updateMall(@Param("m") MallSettingBean mallSettingBean);

    //商城设置删除
    @Update("<script>" +
            "update t_mall_setting_info" +
            "<set>" +
            " del_status = '1'" +
            "</set>" +
            "where id = #{i.id}" +
            "</script>")
    int delMall(@Param("m") MallSettingBean mallSettingBean);

}
